﻿<script type="text/javascript">
  function przetwarzaj_dane()
  {
    var brakuje_danych = false;
    var formularz = document.forms['form1'];
    if(!formularz) return;
    
    var tfImie = formularz.imie;
    var tfNazwisko = formularz.nazwisko;
    var tfKraj = formularz.kraj;
    var tfTel = formularz.tel;
    
    tfImie.style.backgroundColor = "#FFFFFF";
    tfNazwisko.style.backgroundColor = "#FFFFFF";
    tfKraj.style.backgroundColor = "#FFFFFF";
    tfTel.style.backgroundColor = "#FFFFFF";
    
    var tylkoLiteryRE = /[a-zA-Z]{2,}/;
    var telefonRE = /[0-9 -]{5,}/;
    var komunikat = "";
    
    if(tylkoLiteryRE.exec(tfImie.value) != tfImie.value){
      komunikat += "imię";
      tfImie.style.backgroundColor = "#FFFF00";
      brakuje_danych = true;
    }
    if(tylkoLiteryRE.exec(tfNazwisko.value) != tfNazwisko.value){
      komunikat += komunikat ? ", nazwisko" : "nazwisko";
      tfNazwisko.style.backgroundColor = "#FFFF00";
      brakuje_danych = true;
    }
    if(tylkoLiteryRE.exec(tfKraj.value) != tfKraj.value){
      komunikat += komunikat ? ", kraj" : "kraj";
      tfKraj.style.backgroundColor = "#FFFF00";
      brakuje_danych = true;
    }
    if(telefonRE.exec(tfTel.value) != tfTel.value){
      komunikat += komunikat ? ", telefon" : "telefon";
      tfTel.style.backgroundColor = "#FFFF00";
      brakuje_danych = true;
    }
    var divKomunikat = document.getElementById('divKomunikat');
    if(!brakuje_danych){
      if(divKomunikat)
        divKomunikat.style.display = "none";
      formularz.submit();
    }
    else{
      if(divKomunikat){
        var str = "W następujących polach są błędne dane: ";
        str += komunikat + ".";
        divKomunikat.innerHTML = str;
        divKomunikat.style.display = "block";
      }
    }
  }
</script>